package com.lingnuo.controller;

import com.lingnuo.pojo.Admin;
import com.lingnuo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AdminController {
    // 自动注入AdminService
    @Autowired
    private AdminService adminService;

    /**
     * 管理员登录
     *
     * @param admin 管理
     * @return {@code String }
     */
    @PostMapping("/admin/login")
    @ResponseBody
    public String adminLogin(@RequestBody Admin admin) {
        Admin result = adminService.adminLogin(admin);
        if (result != null) {
            return "管理员登录成功";
        } else {
            return "管理员登录失败";
        }
    }

    /**
     * 管理员注册
     *
     * @param admin 管理
     * @return {@code String }
     */
    @PostMapping("/admin/register")
    @ResponseBody
    public String adminRegister(@RequestBody Admin admin) {
        int result = adminService.adminRegister(admin);
        if (result > 0) {
            return "管理员注册成功";
        } else {
            return "管理员注册失败";
        }
    }
}